//
//  HJMessageController.swift
//  zhangmiSinweibo
//
//  Created by zhangmi on 16/5/19.
//  Copyright © 2016年 Paramount Pictures. All rights reserved.
//

import UIKit

class HJMessageController: HJBaseTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
    visitorLoginView.updateUI("登录后，别人评论你的微博，发给你的消息，都会在这里收到通知", imageName: "visitordiscover_image_message")
        
    navigationItem.rightBarButtonItem = UIBarButtonItem( title: "show", target: self, action: #selector(HJMessageController.changeBadgeValue))

                tabBarItem.badgeValue = "\(10)"
        setBackgroud()
    }
    
       @objc private func changeBadgeValue() {
          tabBarItem.badgeValue = nil
        tabBarItem.badgeValue = "\(random() % 100)"
     }
    
    
    //设置背景图片
    private func setBackgroud() {
        for subView in self.tabBarController!.tabBar.subviews {
            if subView.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                for v in subView.subviews {
                    if v.isKindOfClass(NSClassFromString("_UIBadgeView")!) {
                        for bgView in v.subviews {
                            if bgView.isKindOfClass(NSClassFromString("_UIBadgeBackground")!) {
                                print(bgView, "别相信你的眼睛!")
                           
                                let image = UIImage(named: "main_badge")
                                //调用 _UIBadgeBackground类型的对象的KVC方法 简介设置值
                                bgView.setValue(image, forKey: "_image")
                            }
                        }
                    }
                }
            }
        }
    }
}
